import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

object Demo3{
  def main(args :Array[String]) : Unit={
    val conf = new SparkConf().setMaster("local[2]").setAppName("app")
    val ssc = new StreamingContext(conf,Seconds(2))

    val lines =ssc.socketTextStream("10.8.16.222",9999)
    val words = lines.flatMap(_.split(" "))
    val pair = words.map(x => (x,1))
    val count = pair.reduceByKey((x,y) => x + y)
    count.print()

    ssc.start()
    ssc.awaitTermination()
  }
}